layui.use(['form','table','element','laytpl','layer','upload','laydate'], function() {
  var table = layui.table;
  var form = layui.form;
  var laydate = layui.laydate;
  var upload = layui.upload;
  //时间选择器
  laydate.render({
    elem: '#chengli'
    ,type: 'date'
  });
  upload.render({
		elem : '#uploader',
		url : '/ssm/file/uploadImage.do',
		done : function(res) {
			if (res.code == '01') {
				$("#uploader")
						.html(
								"<img src='" + res.body + "' style='width: 100px;height: 130px;'/><p>点击重新上传，或将文件拖拽到此处</p>");
				$("#banner_path").val(res.body);
			} else {
				layer.alert("上传失败");
			}
		}
	});

  	init();
    function init(){
        $.post('/ssm/company/findById.do',function(data){
        	var data = data.body;
        	if(data!=null){
                $("#editForm input[id=id]").val(data.id);
                $("#editForm input[id=company_name]").val(data.company_name);
                $("#editForm input[id=company_no]").val(data.company_no);
                $("#editForm input[id=xingzhi]").val(data.xingzhi);
                $("#editForm input[id=chengli]").val(data.chengli);
                $("#editForm input[id=zhuce_zijin]").val(data.zhuce_zijin);
                $("#editForm textarea[id=jianjie]").val(data.jianjie);
                $("#editForm input[id=consumer_id]").val(data.consumer_id);
   
        	}
            form.render('select');
        })
    }

    	//表单提交事件
    layui.form.on('submit(btnSubmit)', function(data){
    		var postData = {
    				id : $("#id").val(),
    				company_name : $("#company_name").val(),
    				company_no : $("#company_no").val(),
    				xingzhi : $("#xingzhi").val(),
    				chengli : $("#chengli").val(),
    				zhuce_zijin : $("#zhuce_zijin").val(),
    				jianjie : $("#jianjie").val(),
    				consumer_id : $("#consumer_id").val(),
    	
    		}
            var qUrl="/ssm/company/save.do";
            $.post(qUrl,postData,function(res){
             if(res.code=="01"){
                 layer.closeAll();
                 layer.msg("保存成功");
                 location.reload();
             }else{
                 layer.msg("保存失败");
             }
         });
            return false;
    });

    
});